package main

import (
	"fmt"
	"time"
)

func main() {
	//基础switch语句
	i := 2
	switch i {
	case 1:
		fmt.Println("one")
	case 2:
		fmt.Println("two")
	case 3:
		fmt.Println("three")
	}

	//多个条件逗号隔开
	switch time.Now().Weekday() {
	case time.Saturday, time.Sunday:
		fmt.Println("it is the weekend")
	default:
		fmt.Println("it is weekday")
	}

	//switch没有表达式，在case中判断
	t := time.Now()
	switch {
	case t.Hour() < 12:
		fmt.Println("it is before noon")
	default:
		fmt.Println("it is after noon")
	}

	//用switch判断参数类型
	whatAmI := func(i interface{}) {
		switch t := i.(type) {
		case bool:
			fmt.Println("bool")
		case int:
			fmt.Println("int")
		default:
			fmt.Println(t)
		}
	}

	whatAmI(false)
	whatAmI("hi")
	whatAmI(1)

	//需要继续下一一分支支,可使用用 fallthrough,但不再判断条件
	x := 10
	switch x {
	case 10:
		fmt.Println("a")
		fallthrough
	case 0:
		fmt.Println("b")
	}
}
